import { ApiProperty } from '@nestjs/swagger';
import { IsString, IsNumber, IsOptional, IsEnum, IsNotEmpty } from 'class-validator';

// 支持的站点枚举
export enum SupportedSite {
  QIDIAN = 'qidian',
  FANQIE = 'fanqie',
  FEILU = 'feilu',
  QIMAO = 'qimao',
}

// 分类映射请求DTO
export class CategoryMappingDto {
  @ApiProperty({ description: '站点名称', example: 'qidian' })
  @IsString()
  @IsNotEmpty()
  @IsEnum(SupportedSite)
  site: string;

  @ApiProperty({ description: '站点分类名称', example: '玄幻' })
  @IsString()
  @IsNotEmpty()
  siteCategory: string;

  @ApiProperty({ description: '母分类ID', example: 1 })
  @IsNumber()
  masterId: number;

  @ApiProperty({ description: '映射说明', required: false })
  @IsString()
  @IsOptional()
  description?: string;
}

// 批量分类映射请求DTO
export class BatchCategoryMappingDto {
  @ApiProperty({
    description: '分类映射列表',
    type: [CategoryMappingDto],
    example: [
      { site: 'qidian', siteCategory: '玄幻', masterId: 1 },
      { site: 'qidian', siteCategory: '都市', masterId: 5 },
    ]
  })
  @IsNotEmpty()
  mappings: CategoryMappingDto[];
}

// 分类映射响应DTO
export class CategoryMappingResponseDto {
  @ApiProperty({ description: '站点名称' })
  site: string;

  @ApiProperty({ description: '站点分类名称' })
  siteCategory: string;

  @ApiProperty({ description: '母分类信息' })
  masterCategory: {
    id: number;
    name: string;
    keywords: string;
    description?: string;
  };

  @ApiProperty({ description: '映射说明' })
  description?: string;
}

// 母分类响应DTO
export class MasterCategoryResponseDto {
  @ApiProperty({ description: '母分类ID' })
  id: number;

  @ApiProperty({ description: '母分类名称' })
  name: string;

  @ApiProperty({ description: '推荐关键词' })
  keywords: string;

  @ApiProperty({ description: '分类描述' })
  description?: string;

  @ApiProperty({ description: '排序权重' })
  sortOrder: number;
}

// 分类映射查询参数DTO
export class CategoryMappingQueryDto {
  @ApiProperty({ description: '站点名称', required: false })
  @IsString()
  @IsOptional()
  @IsEnum(SupportedSite)
  site?: string;

  @ApiProperty({ description: '页码', example: 1, required: false })
  @IsNumber()
  @IsOptional()
  page?: number = 1;

  @ApiProperty({ description: '每页数量', example: 20, required: false })
  @IsNumber()
  @IsOptional()
  limit?: number = 20;
}